let User = require('../b/User')
class UserMgr {
    constructor () {
        this.users = new Map()
    }
    static i () {
        if (!this.instance) {
            this.instance = new UserMgr();
        }
        return this.instance
    }
    create_user (ws, id = 0) {
        if (this.users.has(id)) {
            return this.users.get(id)
        }
        let user = new User(ws, id)
        this.users.set('u_' + id, user)
        return user
    }
    add_user(uid, user) {
        this.users.set('u_' + uid, user)
    }
    get_user (id) {
        return this.users.get('u_' + id)
    }
    remove_user (id) {
        this.users.delete('u_' + id)
    }
    has_user (id) {
        this.users.has('u_' + id)
    }
}
module.exports = UserMgr